package com.douqu.game.core.entity;

import com.douqu.game.core.database.model.ServerModel;
import com.douqu.game.core.util.Utils;


/**
 * Created by bean on 2017/7/28.
 */
public class WorldInfo extends EntityObject {

    private int id;

    private int goodsIndex;

    private int playerIndex;

    private int battleId;

    public void load(ServerModel serverModel)
    {
        if(serverModel == null)
            return;

        id = serverModel.getId();
        goodsIndex += serverModel.getGoodsIndex();
        playerIndex += serverModel.getPlayerIndex();
        battleId = 10000;
    }


    public ServerModel createModel(byte[] arenaRankData)
    {
        ServerModel serverModel = new ServerModel();
        serverModel.setId(id);
        serverModel.setPlayerIndex(goodsIndex);
        serverModel.setGoodsIndex(playerIndex);
        serverModel.setArenaRank(arenaRankData);
        return serverModel;
    }


    /**
     * 获取新的物品流水号
     * @return
     */
    public String createGoodsIndex()
    {
        return id + "-" + Utils.createUUID(5) + "-" + (int) (Math.random() * 9000 + 1000) + "-" + (++goodsIndex);
    }

    /**
     * 获取新的玩家流水号
     * @return
     */
    public String createPlayerIndex(int userId)
    {
        return id + "-" + (++playerIndex) + "-" + Utils.createUUID(5) + "-" + userId;
    }

    public int getServerId()
    {
        return id;
    }

    public String createBattleId()
    {
        return id + "-" + (++battleId) + "-" + Utils.createUUID(4);
    }



    public int getGoodsIndex() {
        return goodsIndex;
    }

    public void setGoodsIndex(int goodsIndex) {
        this.goodsIndex = goodsIndex;
    }

    public int getPlayerIndex() {
        return playerIndex;
    }

    public void setPlayerIndex(int playerIndex) {
        this.playerIndex = playerIndex;
    }


}
